import json
# 读取GeoJSON文件
with open('./geojson/liaoning.json', 'r', encoding = 'utf-8') as f:
  geojson_data = json.load(f)

# 初始化边界框的经纬度范围
min_lon, min_lat = float('inf'), float('inf')
max_lon, max_lat = float('-inf'), float('-inf')

# 遍历GeoJSON中的特征（features）
for feature in geojson_data['features']:
  geometry = feature['geometry']
  if geometry['type'] == 'Polygon':
    # 如果是多边形，遍历所有环
    for ring in geometry['coordinates']:
      for point in ring:
        lon, lat = point
        if lon < min_lon:
          min_lon = lon
        if lat < min_lat:
          min_lat = lat
        if lon > max_lon:
          max_lon = lon
        if lat > max_lat:
          max_lat = lat
  elif geometry['type'] == 'MultiPolygon':
    # 如果是多多边形，遍历所有多边形
    for polygon in geometry['coordinates']:
      for ring in polygon:
        for point in ring:
          lon, lat = point
          if lon < min_lon:
            min_lon = lon
          if lat < min_lat:
            min_lat = lat
          if lon > max_lon:
            max_lon = lon
          if lat > max_lat:
            max_lat = lat

# 生成 L.imageOverlay 所需的格式：[[lat1, lon1], [lat2, lon2]]
image_overlay_bounds = [
  [min_lat, min_lon],  # 左下角
  [max_lat, max_lon]  # 右上角
]

# 打印结果
print(image_overlay_bounds)
